
class Solution:
    def removeDuplicates(self, S: str) -> str:
        stack = list()  # 栈可以实现返回上一层循环
        for cha in S:
            if stack and stack[-1] == cha:
                stack.pop()
                continue
            stack.append(cha)
        return ''.join(stack)